<?php
set_time_limit(0); 
include '../c/config.php';

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);

 
$j=0;
$query=$mysqli->query("select phone from uinfo group by phone having count(phone) >1 ");
while ($list=$query->fetch_array()) {
      $phone=$list['phone'];

      //echo $phone;
      //echo "<br />";
     
     $queryD=$mysqli->query("select * from uinfo WHERE phone ='".$phone."' and `ischong` IS NULL   ");
     $i=1;
     $a=array();
     $b=array();
     while ($listD=$queryD->fetch_array()) {
          if (1 == $i) {
               $a=array('createtime'=>$listD['createtime'],'fen'=>$listD['fen'],'name'=>$listD['name'],'id'=>$listD['id'],'idcard'=>$listD['idcard'],'nianji'=>$listD['nianji'], 'uid'=>$listD['uid']);
           } 

           if (1 <  $i) {
               $b=array('createtime'=>$listD['createtime'],'fen'=>$listD['fen'],'name'=>$listD['name'],'id'=>$listD['id'],'idcard'=>$listD['idcard'],'nianji'=>$listD['nianji'], 'uid'=>$listD['uid']);
           }

        $i++;
     }


     if (isset($b['createtime']) && ( $a['createtime'] == $b['createtime'] || $a['fen'] == $b['fen'] || $a['idcard'] == $b['idcard']) ) {
           
                 echo "<br />";
               echo $j.'........yes...........',$phone;
               
               if ($a['name'] == $b['name'] && $a['idcard'] == $b['idcard'] && $a['nianji'] == $b['nianji']  ) {
                     echo "........",$b['id'];
                     echo "<br />";
                
                     if (empty($b['fen'])) {
                     	 $sql="update uinfo set  ischong=1,phone='".$phone."-del' where id='".$b['id']."' ";
                          echo $sql;
                         $mysqli->query($sql);
                     }else{
                        if($b['fen'] < $a['fen']){
                             $sql="update uinfo set  ischong=1,phone='".$phone."-del' where id='".$b['id']."' ";
                             $mysqli->query($sql);
                        }else{
                        	$sql="update uinfo set  ischong=1,phone='".$phone."-del' where id='".$a['id']."' ";
                             $mysqli->query($sql);
                        }


                     }

                     
                    
                     echo "<br /><br />";

               }

               echo "<br />";


               $j++;
         
          
     }
     
      //SELECT * FROM `d3` WHERE `phone` LIKE '12482633906'


}